// 定义specification控制器
app.controller('specificationController', function ($scope, $controller, specificationService) {

    // 继承父控制器
    $controller('baseController', {$scope: $scope});

    // 定义分页查询
    $scope.findPage = function (page, rows) {
        specificationService.findPage(page, rows).success(function (data) {
            // 总记录数赋值
            $scope.paginationConf.totalItems = data.total;
            // 分页结果
            $scope.list = data.rows;
        })
    };

    // 新增品牌数据
    $scope.add = function () {
        var objService = null;
        if ($scope.entity.specification.id != null) {
            objService = specificationService.update($scope.entity);
        } else {
            objService = specificationService.add($scope.entity);
        }
        objService.success(function (data) {
            if (data.success) {
                $scope.reloadList();
            } else {
                alert(data.message);
            }
        })
    };

    // 通过id查询品牌数据
    $scope.findById = function (id) {
        specificationService.findById(id).success(function (data) {
            $scope.entity = data;
        })
    };

    // 删除品牌数据
    $scope.dele = function () {
        specificationService.dele($scope.ids).success(function (data) {
            if (data.success) {
                // 清空数组
                $scope.ids = [];
                // 刷新
                $scope.reloadList();
            } else {
                alert(data.message);
            }
        })
    }

    // 新增选项行
    $scope.addTableRow = function () {
        $scope.entity.specificationOptionList.push({});
    };
    // 批量选项删除
    $scope.deleteTableRow = function (index){
        $scope.entity.specificationOptionList.splice(index,1);
    }
});